<?php
declare (strict_types=1);

namespace app\common\event\subscribes\category\admin;

use app\admin\logic\system\Log;
use think\Event;

class Category
{
    public function subscribe(Event $event)
    {
        /** 新建 */
        $event->listen('CategoryCreated', function ($category) {
            Log::write($this->getTypeText($category->category_type) . '【' . $category->title . '】', 'category', 'create');
        });
        /** 更新 */
        $event->listen('CategoryUpdated', function ($category) {
            Log::write($this->getTypeText($category->category_type) . '【' . $category->title . '】的信息', 'category', 'update');
        });
        /** 删除 */
        $event->listen('CategoryDeleted', function ($category) {
            Log::write($this->getTypeText($category->category_type) . '【' . $category->title . '】', 'category', 'delete');
        });

    }

    protected function getTypeText($type = 0)
    {
        $text = [
            0 => '课程分类',
            1 => '讲师分类',
            2 => '机构分类',
            3 => '考试分类',
            4 => '文库分类',
            5 => '资讯分类',
            6 => '商品分类'
        ];

        return $text[$type] ?? '未知';
    }
}
